package com.acerola.mrpc.serializer;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: mrpc
 * @description: 序列化工厂类
 * @author: Acerola
 * @create: 2022-12-10 20:57
 **/
public class SerializerManager {
    private final static ConcurrentHashMap<Byte, ISerializer> serializer = new ConcurrentHashMap<>();

    static {
        FastJson2 fastJson2 = new FastJson2();
        Jdk jdk = new Jdk();
        serializer.put(fastJson2.getType(), fastJson2);
        serializer.put(jdk.getType(), jdk);
    }

    public static ISerializer getSerializer(byte key) {
        ISerializer iSerializer = serializer.get(key);
        if (serializer == null) {
            return new Jdk();
        } else {
            return iSerializer;
        }
    }
}
